package goleetcode

type FrequencyTracker struct {
	freq     map[int]int
	freq_cnt map[int]int
}

func Constructor() FrequencyTracker {
	return FrequencyTracker{
		freq:     map[int]int{},
		freq_cnt: map[int]int{},
	}
}

func (feqT *FrequencyTracker) Add(number int) {
	(*feqT).freq_cnt[(*feqT).freq[number]]--
	(*feqT).freq[number]++
	(*feqT).freq_cnt[(*feqT).freq[number]]++
}

func (feqT *FrequencyTracker) DeleteOne(number int) {
	if (*feqT).freq[number] == 0 {
		return
	}

	(*feqT).freq_cnt[(*feqT).freq[number]]--
	(*feqT).freq[number]--
	(*feqT).freq_cnt[(*feqT).freq[number]]++
}

func (feqT *FrequencyTracker) HasFrequency(frequency int) bool {
	return (*feqT).freq_cnt[frequency] > 0
}
